import socket
import threading

def handle_connection(client_socket,address):
    while True:
        msg = client_socket.recv(1024)
        if msg.decode("utf-8")=="exit":
            client_socket.send("bye".encode("utf-8"))
            client_socket.close()
            return
        ret_msg = input()
        client_socket.send(ret_msg.encode("utf-8"))
def server():

    # 声明ipv4,面向连接的协议TCP
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # 绑定端口
    server.bind(('0.0.0.0', 8000))

    # 监听
    server.listen()

    while True:
        s, address = server.accept()
        client_threading=threading.Thread(target=handle_connection,args=(s,address))
        client_threading.start()


if __name__ == '__main__':
    server()